#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QFileInfoList>
#include <QString>
#include <QDir>
#include <QMessageBox>
#include <QImage>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_btnOpen_clicked()
{
    QString filePath = ui->inputDirPath->text();
    QDir dir(filePath);
    // 判断文件夹是否存在
    if(dir.exists()){
        ui->listWidget->clear();
        QFileInfoList info_list = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
        for(int i =0;i<info_list.count();i++){
            ui->listWidget->addItem(info_list.at(i).fileName());
        }
    }
    else{
        QMessageBox::information(this,"提示！","文件夹不存在");
    }

}

void MainWindow::on_listWidget_itemClicked(QListWidgetItem *item)
{
    QDir filePath(ui->inputDirPath->text());
    QString fullName = filePath.absoluteFilePath(item->text());
    QImage img(fullName);
    QImage thumb = img.scaled(ui->label->width(),ui->label->height(),Qt::KeepAspectRatio);
    ui->label->setPixmap(QPixmap::fromImage(thumb));
}




